<!DOCTYPE html>
<html lang="zh-cn">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Pragma" content="no-cache" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<title>网站信息</title>
		<link rel="stylesheet" href="../css/pintuer.css">
		<link rel="stylesheet" href="../css/admin.css">
		<script src="../js/jquery-3.2.1.min.js"></script>
		<script src="../js/pintuer.js"></script>
		<script src="../js/echarts.common.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body>
		<div class="panel admin-panel">
			<div class="panel-head"><strong><span class="icon-pencil-square-o"></span> 网站信息</strong></div>
			<div class="body-content">
				<form method="post" class="form-x" action="">
					<div class="form-group">
						<div class="label">
							<label></label>
						</div>

						<div>
							<div id="main" style="width: 600px;height:400px; float: left;"></div>
							<div id="pietu" style="width: 600px;height:400px;float: left;"></div>
						</div>
						<div class="field">
							<button class="button bg-main icon-check-square-o">刷新</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script type="text/javascript">
			// 基于准备好的dom，初始化echarts实例
			var myChart = echarts.init(document.getElementById('main'));
			var pieChart = echarts.init(document.getElementById('pietu'));
			// 指定图表的配置项和数据
			var option = {
				title: {
					text: '点击量排名前6的数据'
				},
				tooltip: {},
				legend: {
					data: ['销量']
				},
				xAxis: {
					data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
				},
				yAxis: {},
				series: [{
					name: '销量',
					type: 'bar',
					data: [5, 20, 36, 10, 10, 20]
				}]
			};
			var names = []; //类别数组（实际用来盛放X轴坐标值）
			var nums = []; //销量数组（实际用来盛放Y坐标值）
			var result;
			// 使用刚指定的配置项和数据显示图表。
			myChart.setOption(option);
			myChart.showLoading();
			$.ajax({
				type: "post",
				url: "getAttention.action",
				data: {},
				dataType: "json",
				success: function(result) {
					result = JSON.parse(result);
					if(result) {
						console.log(result.data.length);
						for(var i = 0; i < result.data.length; i++) {
							names.push(result.data[i].bookname);
							//console.log(result[i].bookname)
							//挨个取出类别并填入类别数组
						}
						for(var i = 0; i < result.data.length; i++) {
							nums.push(result.data[i].attention);
							//console.log(result[i].attention);
							//挨个取出销量并填入销量数组
						}

						myChart.hideLoading(); //隐藏加载动画
						myChart.setOption({ //加载数据图表
							axisLabel: {
								interval: 0
							},
							legend: {
								data: ['销量']
							},
							xAxis: {
								data: names
							},
							series: [{
								// 根据名字对应到相应的系列
								name: '点击量',
								data: nums
							}]
						});

					}
				},
				error: function(errorMsg) {
					//请求失败时执行该函数
					alert("图表请求数据失败!");
					myChart.hideLoading();
				}
			});
			
			
			option1 = {
				tooltip: {
					trigger: 'axis',
					axisPointer: {
						type: 'cross',
						crossStyle: {
							color: '#999'
						}
					}
				},
				toolbox: {
					feature: {
						dataView: {
							show: true,
							readOnly: false
						},
						magicType: {
							show: true,
							type: ['line', 'bar']
						},
						restore: {
							show: true
						},
						saveAsImage: {
							show: true
						}
					}
				},
				legend: {
					data: ['蒸发量', '降水量', '平均温度']
				},
				xAxis: [{
					type: 'category',
					data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
					axisPointer: {
						type: 'shadow'
					}
				}],
				yAxis: [{
						type: 'value',
						name: '水量',
						min: 0,
						max: 250,
						interval: 50,
						axisLabel: {
							formatter: '{value} ml'
						}
					},
					{
						type: 'value',
						name: '温度',
						min: 0,
						max: 25,
						interval: 5,
						axisLabel: {
							formatter: '{value} °C'
						}
					}
				],
				series: [{
						name: '蒸发量',
						type: 'bar',
						data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
					},
					{
						name: '降水量',
						type: 'bar',
						data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
					},
					{
						name: '平均温度',
						type: 'line',
						yAxisIndex: 1,
						data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]
					}
				]
			};
		  pieChart.setOption(option1);
		</script>
	</body>

</html>